﻿using System;

namespace MathService.DSP
{
    public static class SimpleSignalGenerator
    {
        public static double[] CreateSignal(Converter<double, double> Function, double dt, int Length)
        {
            var lv_Result = new double[Length];

            for(var i = 0; i < Length; i++)
                lv_Result[i] = Function(i * dt);

            return lv_Result;
        }

        public static double[] Exponential(double A, double alpha, double t0, double s0, double dt, int Length)
        {
            return CreateSignal(t => A * Math.Exp(alpha * (t - t0)) + s0, dt, Length);
        }

        public static double[] Impulse_Single(double A, double t0, double t1, double t2, double dt, int Length)
        {
            return CreateSignal(t =>
                                    {
                                        t -= t0;
                                        return t > t1 && t < t2
                                            ? A
                                            : (Math.Abs(t - t1) < double.Epsilon || Math.Abs(t - t2) < double.Epsilon
                                                ? A / 2
                                                : 0);
                                    }, dt, Length);
        }
    }
}
